package com.huadi.ssm.Controller;

import com.huadi.ssm.Service.FireService;
import com.huadi.ssm.po.Fire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/fire")
public class FireController {
    @Autowired
    @Qualifier("FireImpl")
    private FireService fireService;

    //1:查询所有并返回界面
    @RequestMapping("/allfire")
    public String allfire(Model model){
        List<Fire> fires=fireService.findAllFire();
        model.addAttribute("fires",fires);
        return "allfire";

    }

    //2：跳转到增加界面
    @RequestMapping("/toaddfire")
    public String toaddfire(){return "allfire";}

    //3:增加操作
    @RequestMapping("/addfire")
    public String addfire(Fire fire){
        fireService.addFire(fire);
        return "redirect:/fire/allfire";
    }

    //4：删除
@RequestMapping("/deletefire")
    public String deletefire(String fireId){
        fireService.deleteFireById(fireId);
        return "redirect:/fire/allfire";
}
    //5:更新

    @RequestMapping("/toupdatefire")
    public String toupdatefire(){return "updatefire";}


    @RequestMapping("/updatefire")
    public String updatefire(Fire fire){
        fireService.updateFire(fire);
        return "redirect:/fire/allfire";
    }

    //6:根据ID查找

    @RequestMapping("/onefire")
    public String onefire(String fireId){
       Fire fire= fireService.findFireById(fireId);
        return "暂定";
    }


}
